from appium import webdriver
from appium.options.android import UiAutomator2Options
from selenium.webdriver.support.wait import WebDriverWait
from pages.base_page import BasePage
from appium.webdriver.common.appiumby import AppiumBy as By


class CollectPage(BasePage):
    #定位器
    enter_collect_locator = (By.XPATH, '//android.widget.TextView[@text="所有菜谱"]')
    all_cookbook_locator = (By.XPATH, '//android.widget.TextView[@text="所有菜谱"]')
    first_cookbook_locator = (By.XPATH,'//android.widget.ImageView[@resource-id="com.xiachufang:id/round_hollow"]')
    first_cookbook_info_locator = (By.XPATH,'//android.widget.TextView[@resource-id="com.xiachufang:id/recipe_bto_nav_bar_publish"]')
    menu_locator = (By.XPATH,'//android.widget.TextView[@text="菜单"]')
    first_menu_locator = (By.XPATH,'//android.widget.TextView[@resource-id="com.xiachufang:id/board_title" and @text="菜单1"]')
    first_menu_info_locator = (By.ID,'com.xiachufang:id/board_detail_title_text')
    course_locator = (By.XPATH,'//android.widget.TextView[@text="课程"]')
    history_locator = (By.XPATH,'//android.widget.TextView[@text="浏览历史"]')
    history_first_locator =(By.XPATH,'(//android.widget.ImageView[@resource-id="com.xiachufang:id/round_hollow"])[1]')
    history_first_info_locator = (By.XPATH,'//android.widget.TextView[@resource-id="com.xiachufang:id/recipe_bto_nav_bar_publish"]')
    search_box_locator = (By.XPATH,'//android.widget.EditText[@resource-id="com.xiachufang:id/search_edit_text"]')
    search_btn_locator = (By.XPATH,'//android.widget.TextView[@text="搜索"]')
    search_info_locator = (By.XPATH,'//android.widget.TextView[@text="综合"]')

    #获取收藏界面的返回信息
    def get_enter_collect_info(self):
        return self.driver.find_element(*self.enter_collect_locator).text
    #点击所有菜谱
    def click_all_cookbook(self):
        self.driver.find_element(*self.all_cookbook_locator).click()
    #点击收藏的第一个菜谱
    def click_first_cookbook(self):
        self.driver.find_element(*self.first_cookbook_locator).click()
    #返回点击第一个收藏的信息
    def get_first_cookbook_info(self):
        return self.driver.find_element(*self.first_cookbook_info_locator).text
    #点击菜单
    def click_menu(self):
        self.driver.find_element(*self.menu_locator).click()
    #返回菜单的信息
    def get_menu_info(self):
        return self.driver.find_element(*self.menu_locator).text
    #点击第一个菜单
    def click_first_menu(self):
        self.driver.find_element(*self.first_menu_locator).click()
    #返回点击第一个菜单的信息
    def get_first_menu_info(self):
        return self.driver.find_element(*self.first_menu_info_locator).text
    #点击课程
    def click_course(self):
        self.driver.find_element(*self.course_locator).click()
    #获取点击课程后的返回信息
    def get_course_info(self):
        return self.driver.find_element(*self.course_locator).text
    #点击浏览历史
    def click_history(self):
        self.driver.find_element(*self.history_locator).click()
    #返回进入浏览历史的信息
    def get_history_info(self):
        return self.driver.find_element(*self.history_locator).text

    #点击浏览历史第一个
    def click_history_first(self):
        self.driver.find_element(*self.history_first_locator).click()
    #返回点击浏览历史第一个的信息
    def get_history_first_info(self):
        return self.driver.find_element(*self.history_first_info_locator).text

    #点击搜索框
    def click_search_box(self):
        self.driver.find_element(*self.search_box_locator).click()
    #输入搜索内容
    def input_search_box(self,search_content):
        self.driver.find_element(*self.search_box_locator).send_keys(search_content)
    #点击搜索按钮
    def click_search_btn(self):
        self.driver.find_element(*self.search_btn_locator).click()
    #返回搜索后的信息
    def get_search_info(self):
        return self.driver.find_element(*self.search_info_locator).text

